package org.example.common;

import lombok.Data;
import java.util.List;

/**
 * 分页结果包装类
 * @param <T> 数据类型
 */
@Data
public class PageResult<T> {
    
    private List<T> records;  // 数据列表
    private long total;       // 总记录数
    private long size;        // 每页大小
    private long current;     // 当前页码
    private long pages;       // 总页数
    
    public PageResult() {}
    
    public PageResult(List<T> records, long total, long size, long current) {
        this.records = records;
        this.total = total;
        this.size = size;
        this.current = current;
        this.pages = (total + size - 1) / size;  // 计算总页数
    }
    
    /**
     * 是否有下一页
     */
    public boolean hasNext() {
        return current < pages;
    }
    
    /**
     * 是否有上一页
     */
    public boolean hasPrevious() {
        return current > 1;
    }
    
    /**
     * 是否为空
     */
    public boolean isEmpty() {
        return records == null || records.isEmpty();
    }
}